home *** CD-ROM | disk | FTP | other *** search
- '***************************************************************************
- '* QB_LIB1.BAS version 1.02 Last: 02-11-1987 *
- '* *
- '* Author: Ronald G. Earley *
- '* *
- '* These routines are free to the public - use how ever you wish! *
- '***************************************************************************
- ' '
- ' version 1.01 (02-02-1987) added the following functions: '
- ' center.text() '
- ' get.day() '
- ' real.time() '
- ' '
- ' version 1.02 (02-05-1987) added the following functions: '
- ' bios.scroll () '
- ' '
- '--------------------------------------------------------------------------'
-
- dim style%(4,10) ' styles for window drwing
- dim m$(12) ' month names
- dim days$(6) ' day names
- dim m%(12) ' number of days for each month
- dim in.regs%(7) ' registers before bios call
- dim out.regs%(7) ' registers after return of bios call
-
- '============================================================================
-
- SUB elapsed.time (s$,e$,m#) STATIC
-
- ' get starting, ending minutes
- s#=(val(left$(s$,2))*60)+val(mid$(s$,4,2))
- e#=(val(left$(e$,2))*60)+val(mid$(e$,4,2))
-
- ' check if rollover
- ' we can tell if s# > e# i.e. 23:40:00 and 00:15:00
- ' if so, add 1440 to e# (1440 = 24 * 60)
-
- if s#>e# then e#=e#+1440
-
- m#=e#-s#
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB scan.string (a$,s$,c%,case.type%) STATIC
-
- a1$=a$
- s1$=s$
-
- if (case.type%=0) then
- call lower.to.upper (a1$)
- call lower.to.upper (s1$)
- end if
-
- c%=instr(1,a1$,s1$)
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB month.name (month$,month%) STATIC
- shared m$()
-
- m$(1)="January" ' init month names
- m$(2)="February"
- m$(3)="March"
- m$(4)="April"
- m$(5)="May"
- m$(6)="June"
- m$(7)="July"
- m$(8)="August"
- m$(9)="September"
- m$(10)="October"
- m$(11)="November"
- m$(12)="December"
-
- month$=m$(month%)
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB days.after (a$,start.date$,days%) STATIC
-
- m%(1)=31
- m%(2)=28
- m%(3)=31
- m%(4)=30
- m%(5)=31
- m%(6)=30
- m%(7)=31
- m%(8)=31
- m%(9)=30
- m%(10)=31
- m%(11)=30
- m%(12)=31
-
- ' check for leap year
- year%=val(right$(date$,4))
- if (((year% MOD 4)=0 and (year% MOD 100)<>0) or (year% MOD 400)=0) then
- m%(2)=29
- end if
-
- ' add days% onto date
- sm%=val(left$(start.date$,2))
- sd%=val(mid$(start.date$,4,2))
- sy%=val(right$(start.date$,4))
-
- for x%=1 to days%
- sd%=sd%+1
- if (sd%>m%(sm%)) then
- sm%=sm%+1
- end if
- if (sm%>12) then
- sm%=1
- sy%=sy%+1
- end if
- next x%
-
- ' form return date
- sm$=str$(sm%):sm$=string$(2-len(sm$),"0")
- sd$=str$(sd%):sd$=string$(2-len(sd$),"0")
- sy$=str$(sy%):sy$=string$(4-len(sy$),"0")
- a$=sm$+"-"+sd$+"-"+sy$
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB parse.block (count%,parse$,l%(1),a$(1),drop%) STATIC
-
- start%=1
- for x%=0 to count%
- a$(x%)=mid$(parse$,start%,l%(x%))
- if (drop%) then call drop.trailing.spaces (a$(x%))
- start%=start%+l%(x%)
- next x%
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB remove.backspaces (a$) STATIC
-
- c%=len(a$)
- start%=1
- i%=instr(start%,a$,chr$(8))
- while (i%)
- a$=left$(a$,i%-2)+right$(a$,len(a$)-i%)
- start%=i%
- i%=instr(start%,a$,chr$(8))
- wend
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB remove.char (a$,c%) STATIC
-
- start%=1
- i%=instr(start%,a$,chr$(c%))
- while (i%)
- a$=left$(a$,i%-1)+right$(a$,len(a$)-i%)
- start%=i%
- i%=instr(start%,a$,chr$(c%))
- wend
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB wait.for.carrier (modem.status.port%,c#) STATIC
-
- while (c#)
- if (128 AND inp(modem.status.port%)) then EXIT SUB
- c#=c#-1
- wend
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB check.carrier (modem.status.port%,flag%) STATIC
-
- flag%=inp(modem.status.port%) AND 128
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB set.color (a%,b%,c%,d%,type%) STATIC
-
- if (type%=1) then
- color a%,b% ' take monochrome colors
- elseif (type%=0) then
- color c%,d% ' take color colors
- end if
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB clear.kb.buffer STATIC
-
- def seg=0
- poke 1050,peek(1052)
- def seg
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB lower.to.upper (x$) STATIC
-
- a%=len(x$)
- for x%=1 to a%
- c%=asc(mid$(x$,x%,1))
- if (c%>96 and c%<123) then mid$(x$,x%,1)=chr$(c%-32)
- next x%
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB delay (x) STATIC
-
- for td=1 to x
- if inkey$=chr$(27) then td=x+1
- next td
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB drop.trailing.spaces (x$) STATIC
-
- a%=len(x$)
- for x%=a% to 1 step -1
- if mid$(x$,x%,1)=chr$(32) then _
- next x%
- x$=left$(x$,x%)
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB getinp (ypos%,xpos%,length%,csr%,cbuf%,cinp%,bsc%,lb%,ub%,retinp$,kb%,aret%,fg%,bg%) STATIC
-
- STATIC ncc%
- kb%=0
-
- if ypos%>25 or ypos%<0 then EXIT SUB
- if xpos%>80 or xpos%<0 then EXIT SUB
- if length%<0 or length%>32767 then EXIT SUB
- if cbuf% then call clear.kb.buffer
- if cinp% then retinp$=""
- if bsc%=0 then bsc%=32
- if lb%<1 or lb%>255 then lb%=32
- if ub%<1 or ub%>255 then ub%=122
- if fg%<0 or fg%>31 then fg%=15
- if bg%<0 or bg%>7 then bg%=0
-
- getkey:
-
- kb$=inkey$
- ncc%=ncc%+1
- if ncc%>300 then gosub blinkcursor
- if len(kb$)=0 then goto getkey
-
- ' check for single scan code
- while (len(kb$)=1)
- loop%=1
- kb%=asc(kb$)
-
- ' check for characters in input range
- while ((kb%>=lb% and kb%<=ub%) and loop%=1 and len(retinp$)<length%)
- if (ypos%>0 and ypos%<26 and xpos%>0 and xpos%<81) then
- color fg%,bg%
- locate ypos%,xpos%+len(retinp$):print kb$;
- end if
- retinp$=retinp$+kb$
- if (aret%=1 and len(retinp$)=length%) then
- kb%=13
- goto finishup
- end if
- loop%=0
- wend
-
- ' back space
- while (kb%=8 and loop%=1)
- while (len(retinp$)>0 and loop%=1)
- color fg%,bg%
- retinp$=left$(retinp$,len(retinp$)-1)
- locate ypos%,xpos%+len(retinp$)+1
-
- if len(retinp$)=length%-1 then _
- print " "; _
- else _
- print chr$(bsc%);
-
- if (csr%) then
- locate ypos%,xpos%+len(retinp$)
- print chr$(bsc%);
- end if
-
- loop%=0
- wend
- loop%=0
- wend
-
- ' enter, esc
- if ((kb%=13 or kb%=27) and loop%=1) then
- loop%=0
- goto finishup
- end if
-
- ' ctrl-a through ctrl-z
- if ((kb%>0 and kb%<27) and loop%=1) then
- loop%=0
- goto finishup
- end if
-
- kb$=""
- wend
-
- ' check for extended code inputs
- while (len(kb$)=2)
- kb%=asc(right$(kb$,1))
-
- ' add 255 to kb% so we know it is an extended code
- kb%=kb%+255
- loop%=0
- goto finishup
- wend
-
- while (loop%)
- call clear.kb.buffer
- loop%=0
- goto getkey
- wend
-
- goto getkey
-
- blinkcursor:
-
- ncc%=0
- if (csr%=0) then return
- color 7,0
- locate ypos%,xpos%+len(retinp$)
-
- if (blink%) then
- blink%=0
- else
- blink%=1
- end if
-
- if blink%=0 then _
- print chr$(219);:return
- if (blink%=1 and len(retinp$)=length%) then _
- print " "; _
- else _
- print chr$(bsc%);
- return
-
- finishup:
-
- blink%=0
- gosub blinkcursor
-
- EXIT sub
- END SUB
-
- '============================================================================
-
- SUB get.display.type (type%) STATIC
-
- def seg=0
- if (peek(&h410) AND &h30)=&h30 then
- type%=1
- else
- type%=0
- end if
- def seg
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB search.replace (search.string$,find$,replace$,case.type%,r.num%) STATIC
-
- ' check case
- if (case.type%=0) then
- call lower.to.upper (search.string$)
- call lower.to.upper (find$)
- end if
-
- c1%=0 ' current number of s/r
- start%=1
- char.ptr%=instr(start%,search.string$,find$)
-
- while (char.ptr%>0 and c1%<r.num%)
- ' replace text
- l$=left$(search.string$,char.ptr%-1)
- r$=right$(search.string$,len(old$)-char.ptr%)
- search.string$=l$+replace$+r$
- ' set starting position and start search
- start%=start%+len(replace$)
- c1%=c1%+1
- char.ptr%=instr(start%,search.string$,find$)
- wend
-
- r.num%=c1% ' set number of s/r on return
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB draw.window (y1%,x1%,y2%,x2%,c1%,c2%,c3%,c4%,c5%,c6%,h$,s%,ac%,quick%,type%) STATIC
-
- shared style%() ' array containing style information
-
- STATIC isfirst%
- isheader%=0
-
- ' check monitor type - if monochrome, change colors to 15,0
- if (type%) then
- c1%=7:c2%=0
- c3%=7:c4%=0
- c5%=7:c6%=0
- end if
-
- while (isfirst%=0)
- for z%=1 to 4
- for z1%=0 to 10
- read style%(z%,z1%)
- next z1%
- next z%
- isfirst%=1 ' set so routine won't be executed every call
- wend
-
- ' data table for styles - ascii codes as follows:
- ' upper-left,left header brace,left side (also right),lower-left,
- ' bottom (middle,top) line,lower-right,right header brace,upper-right.
- ' styles are numbered 1 - ? where 0 is user definable (ac%)
-
- data 201,204,186,200,205,188,185,187,0,0,0
- data 218,195,179,192,196,217,180,191,0,0,0
- data 213,198,179,212,205,190,181,184,0,0,0
- data 214,199,186,211,196,189,182,183,0,0,0
-
- ' check bounds on passed parameters
- if (y1%<1 or y1%>25 or y2%<1 or y2%>25 or y2%<y1%) then EXIT SUB
- if (x1%<1 or x1%>80 or x2%<1 or x2%>80 or x2%<x1%) then EXIT SUB
- if (c1%<0 or c1%>31) then c1%=7
- if (c2%<0 or c2%>31) then c2%=0
- if (c3%<0 or c3%>31) then c3%=7
- if (c4%<0 or c4%>31) then c4%=0
- if (c5%<0 or c5%>31) then c5%=7
- if (c6%<0 or c6%>31) then c6%=0
- if (s%<0 or s%>4) then EXIT SUB
- if (s%=0 and (ac%<0 or ac%>255)) then EXIT SUB
-
- loop%=1
- while (loop% and s%=0)
- for x%=0 to 10
- style%(0,x%)=ac%
- next x%
- loop%=0
- wend
-
- if len(h$)>0 then isheader%=1 ' if there is a header, set flag
- dwidth%=x2%-x1%-1 ' display width (characters)
-
- ulc%=style%(s%,0) ' upper-left corner
- lhb%=style%(s%,1) ' left header brace
- lrs%=style%(s%,2) ' left,right side
- llc%=style%(s%,3) ' lower-left corner
- bmt%=style%(s%,4) ' bottom,middle,top lines
- lrc%=style%(s%,5) ' lower-right corner
- rhb%=style%(s%,6) ' right header brace
- urc%=style%(s%,7) ' upper-right corner
-
- color c1%,c2% ' upper-left corner,top line,
- locate y1%,x1% ' upper-right corner,left
- print chr$(ulc%);string$(dwidth%,bmt%);chr$(urc%);
-
- loop%=1
- while (isheader% and loop%) ' if a header exists
- d%=dwidth%-len(h$)
- d1%=d%
- d%=int(d%/2)
- if (d%*2)=d1% then d1%=d% else d1%=d%+1
- locate y1%+1,x1%
- color c1%,c2%:print chr$(lrs%);
- color c5%,c6%:print space$(d%);h$;space$(d1%);
- color c1%,c2%:print chr$(lrs%);
- loop%=0
- wend
-
- loop%=1
- while (loop% and isheader%=0)
- locate y1%+1,x1%
- color c1%,c2%:print chr$(lrs%);
- color c5%,c6%:print space$(dwidth%);
- color c1%,c2%:print chr$(lrs%);
- loop%=0
- wend
-
- loop%=1
- while (loop% and isheader%)
- locate y1%+2,x1%
- color c1%,c2%
- print chr$(lhb%);string$(dwidth%,bmt%);chr$(rhb%);
- loop%=0
- wend
-
- loop%=1
- while (loop% and isheader%=0)
- locate y1%+2,x1%
- color c1%,c2%:print chr$(lrs%);
- color c3%,c4%:print space$(dwidth%);
- color c1%,c2%:print chr$(lrs%);
- loop%=0
- wend
-
- start%=y1%+3 ' body of window
-
- for z%=start% to y2%-1
- locate z%,x1%
-
- if quick% then
- color c1%,c2%:print chr$(lrs%);
- locate z%,x1%+dwidth%+1
- color c1%,c2%:print chr$(lrs%);
- else
- color c1%,c2%:print chr$(lrs%);
- color c3%,c4%:print space$(dwidth%);
- color c1%,c2%:print chr$(lrs%);
- end if
- next z%
-
- color c1%,c2% ' bottom line
- locate y2%,x1%
- print chr$(llc%);string$(dwidth%,bmt%);chr$(lrc%);
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB lpt.count (adr%(1),count%) STATIC
-
- count%=0
- offset%=0
-
- def seg=0
- while (peek(&h408+offset%)<>0 and offset%<9)
- adr%(count%)=(peek(&h408+offset%+1)*256)+peek(&h408+offset%)
- count%=count%+1
- offset%=offset%+2
- wend
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB comm.count (adr%(1),count%) STATIC
-
- count%=0
- offset%=0
-
- def seg=0
- while (peek(&h400+offset%)<>0 and offset%<9)
- def seg=0
- adr%(count%)=(peek(&h400+offset%+1)*256)+peek(&h400+offset%)
- count%=count%+1
- offset%=offset%+2
- def seg=0
- wend
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB clear.line (l%) STATIC
-
- if (l%>0 and l%<26) then
- color 7,0
- locate l%,1
- print space$(80);
- end if
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB get.args (c$,arg%,arg$) STATIC
-
- '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ' Returns argument arg.num% from c.line$ in variable arg$
- '
- ' c$ = command line
- ' arg% = argument number
- ' arg$ = argument returned in this var
- '
- ' routine assumes that at least 1 space separates each argument!
- ' i.e. MENU -C -D -X where arg 0 = '-C'
- '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- ' check for null command line
- if (len(c$)=0) then
- arg%=-1
- arg$=""
- EXIT SUB
- end if
-
- temp.c$=c$
- c$=c$+" "
- count%=0
- start%=1
-
- while (count% <= arg%)
- ' find first non space
- while (mid$(c$,start%,1)=chr$(32))
- start%=start%+1
- if (start%>len(c$)) then
- arg%=-1
- arg$=""
- EXIT SUB
- end if
- wend
-
- ' non space found - search until space found
- i%=instr(start%+1,c$,chr$(32))
- arg$=mid$(c$,start%,i%-start%)
- count%=count%+1
-
- ' update starting position pointer
- start%=i%
- wend
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB center.text (l%,d$) STATIC
-
- x%=40-int(len(d$)/2)
- locate l%,x%
- print d$
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB get.day (d$, day$) STATIC
- shared days$()
-
- days$(0)="Sunday" ' init day names
- days$(1)="Monday"
- days$(2)="Tuesday"
- days$(3)="Wednesday"
- days$(4)="Thursday"
- days$(5)="Friday"
- days$(6)="Saturday"
-
- m%=val(left$(d$,2)) ' month
- d%=val(mid$(d$,4,2)) ' day
- y%=val(right$(d$,4)) ' year
-
- if (m%<3) then
- m%=m%+12
- y%=y%-1
- end if
-
- m%=m%+1
-
- ' calculate day
- j=int(365.25*y%)+(int(30.6001*m%)+d%+(17209.82*100))
- temp=j+1-7*int((j+1)/7)
- e=int(temp+.5)
-
- if (y%>2000) then
- day$=" "
- else
- day$=days$(e)
- end if
-
- EXIT SUB
- END SUB
-
- '============================================================================
-
- SUB real.time (t$, rt$) STATIC
-
- rt$=""
- if (t$<"12:00:00") then
- rt$=t$+" AM"
- EXIT SUB
- end if
-
- if (t$<"13:00:00") then
- rt$=t$+" PM"
- else
- a%=val(left$(t$,2))-12
- a$=str$(a%)
- a$=right$(a$,len(a$)-1)
- a$=string$(2-len(a$),"0")+a$
- rt$=a$+right$(t$,6)+ " PM"
- end if
-
- EXIT SUB
- END SUB
-
- SUB bios.scroll (d%,yul%,xul%,ylr%,xlr%,n.lines%) STATIC
- shared in.regs%()
- shared out.regs%()
-
- ax%=0 ' CPU REGISTERS
- bx%=1
- cx%=2
- dx%=3
- bp%=4
- si%=5
- di%=6
- fl%=7
-
- '========================= AX =======================================
- ' set AX register to reflect appropriate scroll
- ' which is set by d% (1=up, 0=down)
- if (d%) then
- in.regs%(ax%)=256*7
- else
- in.regs%(ax%)=256*6
- end if
-
- ' adjust AX - set number of lines to scroll
- in.regs%(ax%)=in.regs%(ax%)+n.lines%
-
- '========================= BX =======================================
- in.regs%(bx%)=&h0700
-
- '========================= CX =======================================
- in.regs%(cx%)=(256*yul%)+xul%
-
- '========================= DX =======================================
- in.regs%(dx%)=(256*ylr%)+xlr%
-
- '==================== CALL INT 10H ===============================
- call INT86(&h10,varptr(in.regs%(0)),varptr(out.regs%(0)))
-
- EXIT SUB
- END SUB
-